<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<meta http-equiv="X-UA-Compatible" content="IE=8">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta content="B2B电商平台" name="description" />
		<meta content="B2B电商平台" name="keyword" />

		<title>B2B电商平台.商品信息</title>
		<link rel="icon" href="include/images/icss.ico" type="image/x-icon" />
		<link rel="shortcut icon" href="include/images/icss.ico" type="image/x-icon" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/include/css/global.css" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/include/css/style.css" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/include/css/pro.css" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/include/css/proManage.css" />
		<link rel="stylesheet" href="<%=path%>/include/JQuery ui/css/smoothness/jquery-ui-1.7.3.custom.css" type="text/css"></link>
		<link rel="stylesheet" type="text/css" href="<%=path%>/include/pagination/page.css" media="all">
			
		<link rel="stylesheet" type="text/css" href="<%=path %>/include/css/mmt_trading.css" />
		<script type="text/javascript" src="<%=path%>/include/js/jquery-1.8.0.min.js"></script>
		<script type="text/javascript" src="<%=path%>/include/js/cookies.js"></script>
		<script type="text/javascript" src="<%=path%>/include/js/icss.busin.js"></script>
		<script type="text/javascript" src="<%=path%>/include/JQuery ui/js/jquery-ui-1.7.3.custom.min.js"></script>
		<script type="text/javascript" src="<%=path%>/include/js/icss.common.js"></script>
		<script type="text/javascript" src="<%=path%>/include/pagination/jquery.pagination.js"></script>
		<script type="text/javascript" src="<%=path%>/include/pagination/init.js"></script>
		<script type="text/javascript" src="<%=path%>/include/js/doT.min.js"></script>
		<script type="text/javascript" src="<%=path%>/include/layer/layer.js"></script>	
		<style type="text/css">
			.table tr td {
				border-left: 1px solid #ddd;
				border-bottom: 1px solid #ddd;
				height: 33px;
			}
			
			.table tr th {
				border-left: 1px solid #ddd;
				font-weight: bold;
			}
			em.create {
			    background-position: -50px -44px;
			    line-height: 28px;
			    display: inline-block;
			    font-style: normal;
			    background-repeat: no-repeat;
			    text-indent: 15px;
			    float: right;
			    cursor: pointer;
			}
			.create {
				background: url("<%=path%>/images/coupons/sort_zss.png");
			}
			a{
				color: #039;
			}
			#tbody td{
				padding: 0px 4px;
				vertical-align: middle;
				line-height: 20px;
			}
			#queryId input{
				height: 24px;
			}
			button {
				width: 44px;
			    height: 24px;
			    line-height: 24px;
			    background-color: transparent;
			    background-repeat: no-repeat;
			    background-position: 0 -203px;
			    border: 0;
			    cursor: pointer;
			    font: 12px/1.5 arial,tahoma,\5b8b\4f53;
			    margin: 0 0 0 5px;
			    outline: none;
			    background-image: url('<%=path%>/include/css/img/xs_bgx.png');
			}
	</style>
	<script type="text/javascript">
	$(function(){
		_search();
	});

	var pagination;
	function _search() {
		var url = "<%=path%>/purchaseGoods/queryProductInfoList.do";
		var data = {
				productName : $("#productName").val()
		};
		pagination = _initPagination({'pageId':'pagination', 'url': url, 'data': data, 'rows': 5, 'callback':_initDataList});
	}
	
	function _initDataList(data) {
	 	var tpl = $('#dataTpl').html();
		$('#tbody').html(doT.template(tpl)(data.rows));
	}	
	

	function _checkAll(){
		var checked = $("#checkAll").is(':checked');
		var productIdStr = $("#productIdStr").val();
		if(checked){
			$("input[name='productId']").each(function(){
				var shopId = this.attr('shopValue');
				productIdStr += ","+shopId+"#@"+this.value
				$(this).attr("checked",'true');
			});
			$("#productIdStr").val(productIdStr);
		}else{
			$("input[name='productId']").each(function(){
				$(this).removeAttr("checked");
			});
			$("#productIdStr").val("0");
		}
	}

	function _clickkInfo(shopId,productId){
		if($("#"+productId).is(':checked'))
			$("#productIdStr").val($("#productIdStr").val()+","+shopId+"#@"+productId);
		else
			$("#productIdStr").val($("#productIdStr").val().replace(","+shopId+"#@"+productId,""));
	}

	function _addBatchProduct(){
		var productIdStr = $("#productIdStr").val();
		if(productIdStr == "0"){
			parent.layer.alert("请选择批量添加的商品");
			return;
		}
		productIdStr = productIdStr.substr(2);
		_addProductInfo(productIdStr,1);
	}
	function _addProductInfo(id,flag){
    	$.ajax({
			type:"post",
			url:"<%=path%>/purchaseGoods/saveSearchProductInfo.do",
			dataType:"json",
			data:{uuids:id},
			success:function(data){
				if(data.success){
					$("#productIdStr").val("0");
					$("#checkAll").removeAttr("checked");
					parent.layer.alert(data.msg);
					_search();
				} else {
					parent.layer.alert(data.msg);
				}
			}
		});
    }
	
</script>
	</head>

	<body style="font-family: '微软雅黑';">
		<div id="contentDiv" style="padding:4px; width:99%;">
			<div class="colnums-2-ab-b" style="overflow-x:auto;">
				<div id="queryId" style="border: 1px solid #e0e0e0;background: #f5f5f5;padding-left:10px;margin-bottom:10px;height: 40px;line-height: 40px;font-size:14px;">
					商品名称:<input id="productName" name="productName" placeholder="请输入商品名称" style="font-size: 12px;height: 24px;width: 110px;padding-left: 3px" type="text" />&nbsp;
					<button class="cxx_btn" type="button" onclick="_search()">查询</button>
					<button style="width: 66px;background-size: 180px 458px;" type="button" onclick="_addBatchProduct()">批量添加</button>
				</div>
				<div class="row-fluid dataTables_wrapper" >
					<table id="listTable"
						class="table table-hover table-nomargin table-bordered usertable dataTable"
						style="width: 100%; border-spacing: 0;">
						<thead>
							<tr class="trBgd"
								style="background-color: #eee;text-align: center; height: 31px; border: 1px solid #ddd; white-space: nowrap; background-position: 0 -123px; line-height: 30px; font-weight: bold;">
								<th>
									<input id="checkAll" type="checkbox" name="checkAll" onclick="_checkAll()" value="" star="3" mainpro="">
									<input type="hidden" id="productIdStr" name="productIdStr" value="0"/>
								</th>
								<th>
									序号
								</th>
								<th>
									图片
								</th>
								<th>
									商品名称
								</th>
								<th>
									建议零售价格
								</th>
								<th>
									购进日期
								</th>
								<th>
									操作
								</th>
								
							</tr>
						</thead>
						<tbody id="tbody" style="font-size: 13px">
						</tbody>
					</table>
					<div class="dataTables_paginate paging_full_numbers">
						<span id="innerHtml"> </span>
					</div>
					<div id="pagination"></div>
					<div>
						<div style="height: 30px;"></div>
						<!-- 分类列表div结束 -->
						<div class="clear"></div>
					</div>
				</div>
				</div>
			</div>
	</body>
	<script type="text/javascript">
	$(document).ready(function(){
			_reHeight("rightFrame","contentDiv");
	 });
</script>
	<script id="dataTpl" type="text/template">
		{{ for (var i = 0; i < it.length; i ++) { }}  
		{{     var row = it[i]; }}
			<tr style='line-height: 20px;white-space: nowrap;'>
				<td style='text-align:center;vertical-align: middle;width:6%;'>
					<input id='{{=row.PRODUCT_ID}}' onclick="_clickkInfo('{{=row.SHOP_ID}}','{{=row.PRODUCT_ID}}')" type="checkbox" name="productId" value="{{=row.PRODUCT_ID}}" shopValue="{{=row.PRODUCT_ID}}" star="3" mainpro="">
				</td>
				<td style='text-align:center;vertical-align: middle;width:6%;'>{{=row.PID}}</td>
				<td style='text-align:left;vertical-align: middle;width:10%;'>
		{{		if(row.PRODUCT_PIC!=''){}} 
					<img src='{{=row.PRODUCT_PIC}}' alt='' resizeimg='true' onmousedown='' onerror='javascript:this.src="<%=path%>/download/error/nopicture.jpg"' style='width: 50px; height: 43.5px;'>
		{{		}}}
				</td>
				<td style='text-align:left;vertical-align: middle;width:30%;'>{{=row.PRODUCT_NAME}}</td>
				<td style='text-align:right;vertical-align: middle;width:13%;'>{{=row.PRODUCT_RETAIL_PRICE}}元</td>
				<td style='text-align:center;vertical-align: middle;width:20%;'>{{=row.CREATE_TIME}}</td>
				<td style='text-align:center;vertical-align: middle;width:15%;border-right: 1px solid #ddd;'>
					<a href="javascript:_addProductInfo('{{=row.SHOP_ID}}#@{{=row.PRODUCT_ID}}',0)">添加</a>
				</td>
		     </tr>
		{{ } }}
	</script>
</html>
